﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Interactivity;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
using System.Collections.Specialized;
using System.Windows.Media.Animation;
    
namespace TouchControls
{
    public class ListItemAnimateScaleBehavior : ListItemAnimateBehaviorBase
    {
        protected override void AnimateItem(Storyboard sb, ListBoxItem item, TimeSpan delay)
        {
            var transform = new ScaleTransform();
            item.RenderTransform = transform;
            string propName = ScaleTransform.ScaleXProperty.Name;
            var name = propName + transform.GetHashCode();
            AssociatedObject.RegisterName(name, transform);
            var animationXHold = this.AddAnimation(sb, TimeSpan.FromMilliseconds(0));
            animationXHold.To = 0;
            animationXHold.Duration = TimeSpan.FromMilliseconds(0);
            
            var animationX = this.AddAnimation(sb, delay);
            animationX.From = 0;
            animationX.To = 1;
            Storyboard.SetTargetName(animationX, name);
            Storyboard.SetTargetProperty(animationX, new PropertyPath(propName));
            Storyboard.SetTargetName(animationXHold, name);
            Storyboard.SetTargetProperty(animationXHold, new PropertyPath(propName));
        }
    }
}
